package com.neusoft.elmboot.mapper;

import org.apache.ibatis.annotations.*;

import com.neusoft.elmboot.po.DailyTotal;
import com.neusoft.elmboot.po.Orders;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface OrdersMapper {
	
	@Insert("insert into orders(userId,businessId,orderDate,orderTotal,daId,orderState) values(#{userId},#{businessId},#{orderDate},#{orderTotal},#{daId},0)")
	@Options(useGeneratedKeys=true,keyProperty="orderId",keyColumn="orderId")
	public int saveOrders(Orders orders);
	
	public Orders getOrdersById(Integer orderId);

	public List<Orders> listOrdersByUserId(String userId);


	@Update("UPDATE orders SET orderState = 1, orderDate = #{currentDate} WHERE orderId = #{orderId} AND orderState = 0")
	public int turnOrderState(@Param("orderId") Integer orderId, @Param("currentDate") String currentDate);

	// @Select("SELECT * FROM orders WHERE userId = #{userId} AND orderState = 1")
	//
	
	//@Select("SELECT * FROM orders WHERE userId = #{userId} AND orderState = 1")
	public List<Orders> listPaidOrdersByUserId(String userId);

	
	@Select("select count(*) from orders where businessId = #{businessId} and orderState=1")
	public int getNumberById(Integer businessId);
		
}
